package com.kye.express.business.vipshop.model;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;

import com.kye.express.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : Joe
 * @version : 1.0
 * @editor : Joe
 * @created : 11/02/2018
 * @updated : 11/02/2018
 * @description : <Description>
 * @update_reason : <UpdateReason>
 */

public class VipExchangeMoneyModel implements Parcelable {

    private int money;
    private String moneyType;
    private boolean isSelected;

    /**
     * 红包编号
     * WPDH001（10元）
     * WPDH002（20元）
     * WPDH003（30元）
     * WPDH004（50元）
     * WPDH005（100元）
     * WPDH006（200元）
     * WPDH007（300元）
     * WPDH008（500元）
     * @return
     */
    public static List<VipExchangeMoneyModel> createDataList(Context context) {
        List<VipExchangeMoneyModel> moneyModels = new ArrayList<>();
        String[] moneyTypes = context.getResources().getStringArray(R.array.vip_exchange_money_type);
        int[] money = context.getResources().getIntArray(R.array.vip_exchange_money_type_amount);
        for (int i = 0; i < 5; i++) {
            VipExchangeMoneyModel moneyModel = new VipExchangeMoneyModel(money[i], moneyTypes[i]);
            moneyModels.add(moneyModel);
        }
        moneyModels.get(0).setSelected(true);
        return moneyModels;
    }

    public VipExchangeMoneyModel(int money, String moneyType) {
        this.money = money;
        this.moneyType = moneyType;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

    public String getMoneyType() {
        return moneyType;
    }

    public void setMoneyType(String moneyType) {
        this.moneyType = moneyType;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.money);
        dest.writeString(this.moneyType);
        dest.writeByte(this.isSelected ? (byte) 1 : (byte) 0);
    }

    public VipExchangeMoneyModel() {
    }

    protected VipExchangeMoneyModel(Parcel in) {
        this.money = in.readInt();
        this.moneyType = in.readString();
        this.isSelected = in.readByte() != 0;
    }

    public static final Parcelable.Creator<VipExchangeMoneyModel> CREATOR = new Parcelable.Creator<VipExchangeMoneyModel>() {
        @Override
        public VipExchangeMoneyModel createFromParcel(Parcel source) {
            return new VipExchangeMoneyModel(source);
        }

        @Override
        public VipExchangeMoneyModel[] newArray(int size) {
            return new VipExchangeMoneyModel[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof VipExchangeMoneyModel)) return false;

        VipExchangeMoneyModel that = (VipExchangeMoneyModel) o;

        return moneyType.equals(that.moneyType);
    }

    @Override
    public int hashCode() {
        return moneyType.hashCode();
    }
}
